package cvut.cz.via.android.adapters;

import java.util.ArrayList;

import cvut.cz.via.android.R;
import cvut.cz.via.android.settings.Setting;
import cvut.cz.via.android.views.SettingsMenuItem;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class SettingsListAdapter extends BaseAdapter {
	
	private ArrayList<Setting> settings;
	private Context context;

	public SettingsListAdapter(ArrayList<Setting> settings, Context context) {
		super();
		this.settings = settings;
		this.context = context;
	}

	public int getCount() {
		return settings.size();
	}

	public Setting getItem(int position) {
		return settings.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		SettingsMenuItem smi;
		if(convertView == null) {
			smi = (SettingsMenuItem)View.inflate(context, R.layout.settings_menu_item, null);	
		} else {
			smi = (SettingsMenuItem)convertView;
		}
		smi.setSetting(settings.get(position));
		return smi;
	}
	
	public void toggleItem(int position) {
		Setting setting = settings.get(position);
		setting.toggleState();
		notifyDataSetChanged();
	}

}
